package com.example.guardian.myadapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;
import com.example.guardian.R;

public class T_CaseAdapter extends BaseAdapter {
    private Context mContext;
    private List<TCase> mList = new ArrayList<>();

    public T_CaseAdapter(Context context, List<TCase> list) {
        mContext = context;
        mList = list;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int i) {
        return mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;
        TCase tCase_item = (TCase) mList.get(i);
        if (view == null) {
            viewHolder = new ViewHolder();
            view = LayoutInflater.from(mContext).inflate(R.layout.tcase_item, null);
            viewHolder.kind_name = (TextView) view.findViewById(R.id.txt_kind_name);
            viewHolder.Tcase_Title = (TextView) view.findViewById(R.id.txt_case_title);
            viewHolder.Tcase_Content = (TextView) view.findViewById(R.id.txt_case_content);
            viewHolder.txt_spread= (TextView) view.findViewById(R.id.spread);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.kind_name.setText(tCase_item.getKind_name());
        viewHolder.Tcase_Title.setText(tCase_item.getCase_name());
        viewHolder.Tcase_Content.setText(tCase_item.getCase_content());
        viewHolder.txt_spread.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemSpreadListener.onSpreadClick(i);
            }
        });
        return view;
    }

    public interface onItemSpreadListener {
        void onSpreadClick(int i);
    }

    private onItemSpreadListener mOnItemSpreadListener;

    public void setOnItemSpreadClickListener(onItemSpreadListener mOnItemSpreadListener) {
        this.mOnItemSpreadListener = mOnItemSpreadListener;
    }

    class ViewHolder {
        TextView kind_name;
        TextView Tcase_Title;
        TextView Tcase_Content;
        TextView txt_spread;
    }

}
